package BLL.User;

import BIZ.UserBiz;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet(name = "ManageCarId", value = "/ManageCarId")
public class ManageCarId extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ManageCarId() {
        super();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();

        //获取表单递送的用户需要修改的电话和邮箱
        String CarNumber1 = new String(request.getParameter("CarNumber1").getBytes(StandardCharsets.UTF_8));
        String CarNumber2 = new String(request.getParameter("CarNumber2").getBytes(StandardCharsets.UTF_8));
        String CarNumber3 = new String(request.getParameter("CarNumber3").getBytes(StandardCharsets.UTF_8));

        //从session获取用户
        String UserName = (String) session.getAttribute("UserName");

        UserBiz userBiz = new UserBiz();
        int managercar1 = userBiz.ChangeCar1(CarNumber1, UserName);
        int managercar2 = userBiz.ChangeCar2(CarNumber2, UserName);
        int managercar3 = userBiz.ChangeCar3(CarNumber3, UserName);

        CarNumber1 = userBiz.getCarId1(UserName);
        session.setAttribute("CarNumber1", CarNumber1);
        CarNumber2 = userBiz.getCarId2(UserName);
        session.setAttribute("CarNumber2", CarNumber2);
        CarNumber3 = userBiz.getCarId3(UserName);
        session.setAttribute("CarNumber3", CarNumber3);

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
